<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>商家管理</title>
    <link rel="stylesheet" type="" href="http://at.alicdn.com/t/font_elc53nn4q4f2mx6r.css">
    <link rel="stylesheet" type="" href="../../sq/css/home.css">
    <style>
        .header { background: #F8F8F8; height: 4rem; position: absolute; z-index: 8; top: 0; left: 0; right: 0; bottom: auto; border-bottom: solid 0.05rem #EEE; }
        .header .center{
            overflow: hidden;
            width: 200px;
            border-radius: 5px;
            border:1px solid #ff6d82;
            height: 30px;
            margin-top: 10px;
            position: absolute;
            left:50%;
            margin-left: -100px;
        }
        .header .center p{
            float: left;
            text-align: center;
            width: 50%;
            margin: 0;
            font-size: 0.6rem;
            line-height: 30px;
            color:#ff6d82;
        }
        .header .center p a {
             color: #666;
        }
        .header{
            overflow: hidden;
            position: relative;
        }
        .center .active{
            background: #ff6d82;
            color: #ffffff !important;
        }
        .back-icon { width: 20px; height: 20px;background-image: url(../../images/arrow_left_b.png); position: absolute; left: 10px; top: 10px; background-position: 50% 50%;background-repeat: no-repeat;
            background-size: 100%; opacity: 0.75}
    </style>
</head>
<body>
<div class="header">
    <a href="index.html" class="back-icon"><i class="back"></i></a>
    <div class="center"><p class="active">线下订单</p><p  ><a href="bs_order_list.html">商圈订单</a></p></div>
</div>
<div class="main">
</div>
<div class="list_loading" style="display: none"><i></i><span>努力加载中...</span></div>
<div class="nodata">没有更多订单了</div>
</body>
</html>
<script type="text/html" id="list">
    <% for(var i = 0;i<list.length;i++){ %>
    <div class="detail">
        <div class="detail_head">
            <div style="width:90%;margin: 0 auto;padding: 15px">
                <img src="../../sq/img/order.png" alt="">
                <div class="order">
                    <div>订单</div>
                    <p><%=list[i].time%></p>
                </div>
                <div class="confirm" id="confirm_<%=list[i]['order_id']%>">
                    <% if (list[i].order_state==20){ %>
                        <% if(list[i].recive==0) { %>
                        等待确认
                        <% } %>
                        <% if(list[i].recive==1) { %>
                        <span style="color: #666">已确认</span>
                        <% } %>
                    <% } %>
                    <% if (list[i].order_state==10){ %>
                    <span style="color: #666">待支付</span>
                    <% } %>
                    <% if (list[i].order_state==0){ %>
                    <span style="color: #666">已取消</span>
                    <% } %>
                </div>
            </div>
        </div>
        <a href="reslute.html?paysn=<%=list[i].order_sn%>" style="color: #666">
        <div>
            <center>
                <div>￥<%=list[i].order_amount%></div>
                <p><%=list[i].buyer_name%> <span style="color:#f98524"><% if(list[i].payment_code=='navgator') { %>线下支付<% }%><% if(list[i].payment_code=='predeposit') { %>余额支付<% }%><% if(list[i].payment_code=='wx_jsapi') { %> 微信支付 <% } %></span></p>
            </center>
        </div>
        </a>
        <div class="detail_foot">
            <div>
                订单编号:<%=list[i].order_sn%>
            </div>
            <% if (list[i].order_state==20){ %>
                <% if(list[i].recive==0) { %>
                <div class="querenshouhuo" id="btn_<%=list[i]['order_id']%>" data-id="<%=list[i]['order_id']%>">
                    确认收款
                </div>
                <% } %>
            <% } %>
        </div>
    </div>
    <% } %>
</script>
<script type="text/javascript" src="../../js/config.js"></script>
<script type="text/javascript" src="../../js/zepto.min.js"></script>
<script type="text/javascript" src="../../js/template.js"></script>
<script type="text/javascript" src="../../js/startmove.js"></script>
<script type="text/javascript" src="../../js/simple-plugin.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script>
    var key = getCookie('key');
    var storeid = getCookie('sqstoreid');
    if(!key||!storeid){
        window.location.href = '/sq/login.html';
    }
    // 获取订单信息
    $.ajax({
        type:"GET",
        url:ApiUrl+"/index.php?act=store&op=offline_order_list",
        dataType:"json",
        data:{key:key,store_id:storeid},
        success:function(res){
            if (res){
                $('.main').html(template.render('list',res));
            }else{
                $('.main').html("<p class='no-data'>赞无数据</p>");
            }
        }
    })

    /**
     *  确认收款
     * */
    $(document).on('click','.querenshouhuo',function(e){

        var id = $(this).attr('data-id');

        $.sDialog({
            skin:"red",
            content:"确认要收款吗？",
            okBtn:true,
            cancelBtn:true,
            okFn: toSubmit, //点击确定按钮执行的函数
        });

        /**
         * 发送收款请求
         * */
        function toSubmit(){
            $.ajax({
                type:"post",
                url:ApiUrl+"/index.php?act=store&op=store_recive",
                data:{key:key,order_id:id},
                dataType:"json",
                success:function(data){
                    if(data['code']==200){
                        data = data.datas;
                        if(data['status']==200){
                            window.location.href = 'reslute.html?paysn='+data.paySn+"&callback=1";
                        }else{
                            creatLayout('收款失败');
                        }
                    }else{

                    }
                }
            })
        }
    });

    var isLock = false;
    var page = 1;
    /**
     * 下拉到底刷新
     */
    $(window).scroll(function () {
        var windowheight=$(window).height();//窗口高度
        var scrolltop=$('body').scrollTop();//滚动条高度
        var eh=$(document).height();//文本高度
        if(parseInt(windowheight+scrolltop+1)>=eh && isLock==false){
            document.getElementsByClassName('list_loading')[0].style.display =' block';
            isLock = true;
            page+=1;
            // 获取订单信息
            $.ajax({
                type:"GET",
                url:ApiUrl+"/index.php?act=store&op=offline_order_list&page="+page,
                dataType:"json",
                data:{key:key,store_id:storeid},
                success:function(res){
                    document.getElementsByClassName('list_loading')[0].style.display =' none';
                    isLock = false;
                    if (res){
                        $('.main').html($('.main').html()+template.render('list',res));
                    }else{
                        isLock = true;
                        $('.nodata').show();
                    }
                }
            })

        }
    })
    function calcRem() {
        var http = document.getElementsByTagName("html")[0];
        var w = document.documentElement.clientWidth;
        http.style.fontSize = w / 32 + "px";
    }
    calcRem();
    window.onresize = function() {
        calcRem();
    };
</script>